package com.yuwei.service;

import com.yuwei.bean.Right;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.*;

@Service
public class RightService {
    private int id = 600;
    private Map<Integer, Right> rightMap = new HashMap<>();

    private void addRight(Right right){
        rightMap.put(right.getId(),right);
    }
    private Right createRight(String authName,String path,int level) {
        Right right = new Right(id);
        right.setAuthName(authName);
        right.setPath(path);
        if(1 == level){
            right.setLevel("1");
        }else if(2 == level){
            right.setLevel("2");
        }else if(3 == level){
            right.setLevel("3");
        }
        id++;
        return right;
    }

    public List<Right> getRightList() {
        List<Right> rights = new ArrayList<>();
        for(int id : rightMap.keySet()){
            Right right = rightMap.get(id);

            rights.add(right);
        }

        return rights;
    }

    public void getRightsTree() {

    }

    @PostConstruct
    void init(){
        Right goodsMgr = createRight("商品管理","goods",1);
        Right child1 = createRight("添加商品", "goods", 2);
        goodsMgr.addRight(child1);
        Right child2 = createRight("商品删除", "goods", 2);
        goodsMgr.addRight(child2);
        Right child3 = createRight("更新商品图片", "goods", 2);
        goodsMgr.addRight(child3);

        addRight(goodsMgr);

        Right orderMgr = createRight("订单管理","orders",1);
        addRight(orderMgr);

        Right rightsMgr = createRight("权限管理","rights",1);
        addRight(rightsMgr);

        Right goodList = createRight("商品列表","goods",2);
        addRight(goodList);

        Right addGoods = createRight("添加商品","goods",3);
        addRight(addGoods);

        Right orderList = createRight("订单列表","orders",2);
        addRight(orderList);
    }
}
